package org.example.j20250911mybites.mybatis.mapper;

import org.apache.ibatis.annotations.*;
import org.example.j20250911mybites.model.UserInfo;

import java.util.List;
@Mapper
public interface UserInfoMapper {
    @ResultMap("resultMap")
    @Select("select * from userinfo")
    List<UserInfo> getUserInfoAll();
    @Select("select * from userinfo where delete_flag = #{deleteFlag}")
    List<UserInfo> getUserInfoByDeleteFlag(Integer deleteFlg);

    @Select("select * from userinfo where delete_flag = #{deleteFlag} and gender= #{gender}")
    List<UserInfo> getUserInfoByDeleteFlag2(Integer deleteFlag,Integer gender);
    @Options(useGeneratedKeys = true ,keyProperty = "id")
    @Insert("insert into userinfo (username,password,age,gender) values(#{username},#{password},#{age},#{gender})")
    Integer insert(UserInfo userInfo);

    @Insert("insert into userinfo (username,password,age,gender) values(#{userInfo.username},#{userInfo.password}," +
            "#{userInfo.age},#{userInfo.gender})")
    Integer insert2(@Param("userInfo") UserInfo userInfo);

    @Delete("delete from userinfo where  id = #{id}")
    Integer delete(Integer id);

    @Update("update userinfo set password = #{password},age = #{age},gender = #{gender} where id = #{id}")
    Integer update(UserInfo userInfo);

    @Select("select id,username,password,age,gender,phone, " +
            "delete_flag as deleteFlag,create_time as createTime,update_time as updateTime " +
            " from userinfo")
    List<UserInfo> selectUserInfos();
    @Results(id = "resultMap",value = {
            @Result(column = "delete_flag", property = "deleteFlag"),
            @Result(column = "create_time", property = "createTime"),
            @Result(column = "update_time", property = "updateTime")
    })
    @Select("select * from userinfo")
    List<UserInfo> selectUserInfos2();

    @Select("select * from userinfo")
    List<UserInfo> selectUserInfos3();
}
